//
//  BIDAddSuggestionAndPraiseViewController.m
//  HJGJCommunity
//
//  Created by mal on 2017/5/22.
//  Copyright © 2017年 mal. All rights reserved.
//

#import "BIDAddSuggestionAndPraiseViewController.h"
#import "BIDSuggestionAndPraiseListViewController.h"
#import "BIDCustomTextView.h"

static NSString *addSuggestionAndPraiseURL = @"feedbackAndroid/add.action";

@interface BIDAddSuggestionAndPraiseViewController ()

@end

@implementation BIDAddSuggestionAndPraiseViewController
@synthesize isSuggestion;

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.title = @"建议与表扬";
    [self.view setBackgroundColor:RGBACOLOR(221.f, 221.f, 230.f, 1.f)];
    _textView.placeholder = isSuggestion ? @"请填写建议内容" : @"请填写表扬内容";
    _textView.inputAccessoryView = self.toolBar;
    //
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"history.png"] style:UIBarButtonItemStylePlain target:self action:@selector(showHistory)];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)showHistory
{
    BIDSuggestionAndPraiseListViewController *vc = [[BIDSuggestionAndPraiseListViewController alloc] init];
    vc.isSuggestion = isSuggestion;
    [self.navigationController pushViewController:vc animated:YES];
}

- (IBAction)submitBtnHandler:(id)sender
{
    NSString *strContent = _textView.text;
    if(strContent.length == 0)
    {
        [self showAlertView:@"内容不能为空" buttonTitle:ALERT_BTN_TITLE tag:0 functionName:nil];
        return;
    }
    NSString *strRequestURL = [[NSString alloc] initWithFormat:@"%@/%@", [AppDelegate getServerAddr], addSuggestionAndPraiseURL];
    NSString *strType = isSuggestion ? @"1" : @"2";
    NSString *strPost = [[NSString alloc] initWithFormat:@"feedback.type=%@&feedback.content=%@&memberId=%@", strType, strContent, [AppDelegate getUserId]];
    [self sendHttpRequestWithURL:strRequestURL postData:strPost withCompletion:^(NSDictionary *responseDic, NSString *errMsg){
        if(errMsg)
        {
            [self showAlertView:errMsg buttonTitle:ALERT_BTN_TITLE tag:0 functionName:nil];
        }
        else
        {
            [self showAlertView:@"提交成功" buttonTitle:ALERT_BTN_TITLE tag:0 functionName:@"alertViewHandler:"];
        }
    }];
}

- (void)alertViewHandler:(id)obj
{
    [self.navigationController popViewControllerAnimated:YES];
}


@end
